<?php

namespace Apps\AppApi\Method\Note;

use Apps\AppApi\Method\BaseMethod;
use PhalconPlus\Api\Common\ResultStatus;
use Apps\Common\Models\AccountBook;


/**
 * 记一笔详情
 * @author      545
 * @date        2016年3月4日
 * @version     1.1.2
 * @copyright   Copyright 2015 meelier.com
 */
class ArrearsInfo extends BaseMethod
{
    
    private $success = 0;
    private $id = 0;

    public function run()
    {
        //验证是否登录
        if(false == $this->verifyUserAuth()){
            return false;
        }
        $ab_id = $this->getDataItem('ab_id',0);
        
        if ($ab_id ==0){
            return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR,"id不能为空");
        }
        $userid = $this->getUserAuth()->userId;

    	//获取记一笔
    	$data = AccountBook::query()
        ->columns(['ab_id', 'ab_cashnum','ab_cardnum','ab_arrears','ab_type','addtime','Apps\Common\Models\AccountBook.remark','i.inorout_id','i.inorout_title','ii.inorout_id as childid','ii.inorout_title as childtitle','m.member_name','ab_cashnum+ab_cardnum as sumnum'])
        ->leftJoin('Apps\Common\Models\Members','Apps\Common\Models\AccountBook.ab_memberid=m.member_id','m')
        ->leftJoin('Apps\Common\Models\Inorout','Apps\Common\Models\AccountBook.ab_innoroutid=i.inorout_id','i')
        ->leftJoin('Apps\Common\Models\Inorout','Apps\Common\Models\AccountBook.child_inoroutid=ii.inorout_id','ii')
        ->where('Apps\Common\Models\AccountBook.user_id = :uid: AND Apps\Common\Models\AccountBook.ab_arrears>0 AND Apps\Common\Models\AccountBook.ab_id = :ab_id:')
        ->bind(['uid'=>$userid,'ab_id'=>$ab_id])
        ->execute()->getFirst();
    	if ($data){
    	    $data->toArray();
    	}
        $this->setResult($data);
        
    }

}